home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 1 / Gold Medal Software Volume 1 (Gold Medal) (1994).iso / prog / tpwprog7.arj / DWIN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1992-07-02  |  2.8 KB  |  121 lines

  1. { dwin.pas -- TDlgWindow demonstration }
  2.  
  3. program DWin;
  4.  
  5. {$R list.res}
  6.  
  7. uses WinTypes, WinProcs, WObjects, Strings;
  8.  
  9. const
  10.  
  11.   id_Dialog  = 200;    { Dialog resource ID }
  12.   id_Add     = 101;    { Dialog control IDs }
  13.   id_Delete  = 102;
  14.   id_Input   = 103;
  15.   id_Listbox = 104;
  16.   inputLen   = 40;     { Maximum length of input edit control }
  17.  
  18. type
  19.  
  20.   DWinApplication = object(TApplication)
  21.     procedure InitMainWindow; virtual;
  22.   end;
  23.  
  24.   PDWinWindow = ^DWinWindow;
  25.   DWinWindow = object(TDlgWindow)
  26.     EditBox: PEdit;
  27.     ListBox: PListBox;
  28.     constructor Init(AParent: PWindowsObject; AName: PChar);
  29.     procedure InitControls;
  30.     procedure SetupWindow; virtual;
  31.     procedure IDAdd(var Msg: TMessage);
  32.       virtual id_First + id_Add;
  33.     procedure IDDelete(var Msg: TMessage);
  34.       virtual id_First + id_Delete;
  35.   end;
  36.  
  37.  
  38. { DWinApplication }
  39.  
  40. {- Initialize DWinApplication object's window }
  41. procedure DWinApplication.InitMainWindow;
  42. begin
  43.   MainWindow := New(PDWinWindow, Init(nil, PChar(id_Dialog)))
  44. end;
  45.  
  46.  
  47. { DWinWindow }
  48.  
  49. {- Construct DWinWindow object }
  50. constructor DWinWindow.Init(AParent: PWindowsObject; AName: PChar);
  51. begin
  52.   TDlgWindow.Init(AParent, AName);
  53.   InitControls
  54. end;
  55.  
  56. {- Initialize control object child windows }
  57. procedure DWinWindow.InitControls;
  58. var
  59.   AControl: PControl;
  60. begin
  61.   AControl := New(PButton,  InitResource(@Self, id_Add));
  62.   AControl := New(PButton,  InitResource(@Self, id_Delete));
  63.   EditBox  := New(PEdit,    InitResource(@Self, id_Input, inputLen));
  64.   ListBox  := New(PListBox, InitResource(@Self, id_Listbox))
  65. end;
  66.  
  67. {- Prepare initial control values }
  68. procedure DWinWindow.SetupWindow;
  69. begin
  70.   TDlgWindow.SetupWindow;
  71.   with ListBox^ do
  72.   begin
  73.     AddString('Apples');
  74.     AddString('Peaches');
  75.     AddString('Pumpkin');
  76.     AddString('Pie')
  77.   end
  78. end;
  79.  
  80. {- Respond to selection of Add button }
  81. procedure DWinWindow.IDAdd(var Msg: TMessage);
  82. var
  83.   Buffer: array[0 .. inputLen] of Char;
  84. begin
  85.   EditBox^.GetText(Buffer, inputLen);
  86.   if StrLen(Buffer) > 0 then
  87.   begin
  88.     ListBox^.AddString(Buffer);
  89.     EditBox^.SetSelection(0, maxint)
  90.   end
  91. end;
  92.  
  93. {- Respond to selection of Delete button }
  94. procedure DWinWindow.IDDelete(var Msg: TMessage);
  95. var
  96.   Item: Word;   { Selected listbox-item index }
  97. begin
  98.   Item := ListBox^.GetSelIndex;
  99.   if Item >= 0 then
  100.   begin
  101.     ListBox^.DeleteString(Item);
  102.     SetFocus(ListBox^.HWindow)
  103.   end
  104. end;
  105.  
  106. var
  107.  
  108.   DWinApp: DWinApplication;
  109.  
  110. begin
  111.   DWinApp.Init('DWinApp');
  112.   DWinApp.Run;
  113.   DWinApp.Done
  114. end.
  115.  
  116.  
  117. {--------------------------------------------------------------
  118.   Copyright (c) 1991 by Tom Swan. All rights reserved.
  119.   Revision 1.00    Date: 5/11/1991
  120. ---------------------------------------------------------------}
  121.